/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved. 
 */
package com.icinfo.cloud.provider.punish.config.controller;

import com.icinfo.cloud.common.core.page.PageResponse;
import com.icinfo.cloud.common.core.Validator.BaseGroup;
import com.icinfo.cloud.provider.punish.config.dto.ConfigBusiParamDocumentInfoDto;
import com.icinfo.cloud.provider.punish.config.dto.ConfigBusiParamDocumentInfoPageRequest;
import com.icinfo.cloud.provider.punish.config.dto.GenDocumentCatalogCodeRequest;
import com.icinfo.cloud.provider.punish.config.model.ConfigBusiParamDocumentInfo;
import com.icinfo.cloud.provider.punish.config.service.IConfigBusiParamDocumentInfoService;
import com.icinfo.cloud.provider.punish.config.vo.ConfigBusiParamDocumentInfoVo;
import com.icinfo.cloud.provider.punish.config.vo.DocumentInfoVo;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import com.icinfo.framework.tools.utils.StringUtils;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 描述: 业务关联文书配置 config_busi_param_document_info 对应的Controller类.<br>
 *
 * @author framework generator
 * @date 2022年02月22日
 */
@RestController
@RequestMapping("/config/busiParamDocumentInfo")
public class ConfigBusiParamDocumentInfoController extends BaseController {
    /**
     * 日志记录器
     */
    private static final Logger logger = LoggerFactory.getLogger(ConfigBusiParamDocumentInfoController.class);

    @Autowired
    private IConfigBusiParamDocumentInfoService configBusiParamDocumentInfoService;
    /**
     * 【V1.0.0】描述：业务关联文书配置分页列表
     * @author liyafeng
     * @date 2022/2/23
      * @param request
     * @return {@link Result< PageResponse< ConfigBusiParamDocumentInfoVo>>}
     */
    @PostMapping("/list")
    public Result<PageResponse<ConfigBusiParamDocumentInfoVo>> list(@RequestBody @Validated ConfigBusiParamDocumentInfoPageRequest request) {
        List<ConfigBusiParamDocumentInfoVo> configBusiParamDocumentInfoVos=configBusiParamDocumentInfoService.getConfigBusiParamDocumentInfoVoList(request);
        return Result.success("查询成功",new PageResponse<>(configBusiParamDocumentInfoVos));
    }
    /**
     *【V1.0.0】描述：业务关联文书配置保存
     * @author liyafeng
     * @date 2022/2/23
      * @param configBusiParamDocumentInfoDto
     * @return {@link Result< String>}
     */
    @PostMapping("/save")
    public Result<String>  save(@RequestBody @Validated(BaseGroup.Insert.class) ConfigBusiParamDocumentInfoDto configBusiParamDocumentInfoDto) {
        return configBusiParamDocumentInfoService.saveConfigBusiParamDocumentInfoDto(configBusiParamDocumentInfoDto);
    }
    /**
     * 【V1.0.0】描述：业务关联文书配置修改
     * @author liyafeng
     * @date 2022/2/23
      * @param configBusiParamDocumentInfoDto
     * @return {@link Result< String>}
     */
    @PostMapping("/edit")
    public Result<String>  edit(@RequestBody @Validated(BaseGroup.Update.class) ConfigBusiParamDocumentInfoDto configBusiParamDocumentInfoDto) {
        return configBusiParamDocumentInfoService.editConfigBusiParamDocumentInfoDto(configBusiParamDocumentInfoDto);
    }
    /**
     * 【V1.0.0】描述：业务关联文书配置获取详情
     * @author liyafeng
     * @date 2022/2/23
     * @param id
     * @return {@link Result< String>}
     */
    @PostMapping("/getdetail/{id}")
    public Result<ConfigBusiParamDocumentInfo> detail(@PathVariable("id") String id){
        return configBusiParamDocumentInfoService.getDetailById(id);
    }
    /**
     * 【V1.0.0】描述：业务关联文书配置删除
     * @author liyafeng
     * @date 2022/2/23
      * @param id
     * @return {@link Result< String>}
     */
    @PostMapping("/del/{id}")
    public Result<String> del(@PathVariable("id") String id){
        return configBusiParamDocumentInfoService.rmById(id);
    }
    /**
     * 【V1.0.0】描述：根据文书目录获取详情
     * @author liyafeng
     * @date 2022/2/25
      * @param documentCatalogCode
     * @return {@link Result< String>}
     */
    @PostMapping("/getDetailByDocumentCatalogCode/{documentCatalogCode}")
    public Result<ConfigBusiParamDocumentInfo> getDetailByDocumentCatalogCode(@PathVariable("documentCatalogCode") String documentCatalogCode){
        ConfigBusiParamDocumentInfo configBusiParamDocumentInfo=configBusiParamDocumentInfoService.getDetailByDocumentCatalogCode(documentCatalogCode);
        return Result.success(configBusiParamDocumentInfo);
    }
    /**
     * 【V1.0.0】描述：生成文书目录编码
     * @author liyafeng
     * @date 2022/2/25
      * @param request
     * @return {@link Result< String>}
     */
    @PostMapping("/genDocumentCatalogCode")
    public Result<String> genDocumentCatalogCode(@RequestBody @Validated GenDocumentCatalogCodeRequest request){
        return configBusiParamDocumentInfoService.genDocumentCatalogCode(request);
    }

    /**
     * 【V1.0.0】描述：根据参数配置id获取所有的参数配置下的文书目录
     * @author liyafeng
     * @date 2022/3/1
      * @param busiParamId
     * @return {@link Result< String>}
     */
    @GetMapping("/getDocumentInfoByBusiParamId")
    public Result<List<DocumentInfoVo>> getDocumentInfoByBusiParamId(String busiParamId){
        if(StringUtils.isBlank(busiParamId)){
            return Result.error("获取失败，参数配置id不能为空");
        }
        List<DocumentInfoVo> documentInfoVos=configBusiParamDocumentInfoService.getDocumentInfoByBusiParamId(busiParamId);
        return Result.success(documentInfoVos);
    }


    /**
     * 【V1.3.2】描述：根据文书目录编码等信息查询文书配置信息
     *
     * @param caseId              案件id
     * @param documentKindCode 文书目录编码
     * @return {@link Result<List<ConfigBusiParamDocumentInfo>>} 文书配置信息列表
     * @author xiangyuyu
     * @date 2022/8/2
     * @since 1.3.2
     */
    @PostMapping("/getDocumentConfigInfoByDocumentCatalogCode")
    @ApiOperation(value = "【V1.3.2】描述：根据文书目录编码等信息查询文书配置信息", httpMethod = "POST")
    public Result<List<ConfigBusiParamDocumentInfo>> getDocumentConfigInfoByDocumentCatalogCode(@RequestParam String caseId, @RequestParam String documentKindCode) {
        List<ConfigBusiParamDocumentInfo> list = configBusiParamDocumentInfoService.getDocumentConfigInfoByDocumentCatalogCode(caseId, null, documentKindCode);
        return Result.success(list);
    }

    /**
     * 【V1.3.2】描述：根据文书种类编码等信息查询文书配置信息
     *
     * @param caseId           案件id
     * @param documentKindCode 文书种类编码
     * @return {@link Result<List<ConfigBusiParamDocumentInfo>>} 文书配置信息列表
     * @author xiangyuyu
     * @date 2022/8/2
     * @since 1.3.2
     */
    @PostMapping("/getDocumentConfigInfoByDocumentKindCode")
    @ApiOperation(value = "【V1.3.2】描述：根据文书目录编码等信息查询文书配置信息", httpMethod = "POST")
    public Result<List<ConfigBusiParamDocumentInfo>> getDocumentConfigInfoByDocumentKindCode(@RequestParam String caseId, @RequestParam String documentKindCode) {
        List<ConfigBusiParamDocumentInfo> list = configBusiParamDocumentInfoService.getDocumentConfigInfoByDocumentKindCode(caseId, null, documentKindCode);
        return Result.success(list);
    }
}